package com.zoshine.zzg.service;

import com.github.pagehelper.util.StringUtil;
import com.zoshine.zzg.dao.GoodsDao;
import com.zoshine.zzg.dao.OrganizationDao;
import com.zoshine.zzg.exception.AppException;
import com.zoshine.zzg.exception.ErrorMessage;
import com.zoshine.zzg.pojo.Goods;
import com.zoshine.zzg.pojo.Organization;
import com.zoshine.zzg.pojo.pojostatus.GoodsStatus;
import com.zoshine.zzg.util.idworker.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 商品serviceImpl
 *
 * @author 田沛凌
 * @time 2017年6月20日 上午11:07:08
 */
@Service
@Transactional
public class GoodsService extends BaseService<Goods> {
//    private IdWorker<Long> goodsIdWorker;
//    private GoodsDao goodsDao;
//    private OrganizationDao organizationDao;
//
//    @Autowired
//    public void setGoodsIdWorker(IdWorker<Long> goodsIdWorker) {
//        this.goodsIdWorker = goodsIdWorker;
//    }
//
//    @Autowired
//    public void setGoodsDao(GoodsDao goodsDao) {
//        this.goodsDao = goodsDao;
//    }
//
//    @Autowired
//    public void setOrganizationDao(OrganizationDao organizationDao) {
//        this.organizationDao = organizationDao;
//    }

//    @Override
//    public Goods getGoods(Long goodsId) {
//        if (goodsId == null || goodsId <= 0) {
//            throw new AppException(ErrorMessage.GOODS_ID_CAN_NOT_BE_NULL_OR_UNDER_ZERO);
//        }
//        return goodsDao.selectOne(goodsId);
//    }

//    @Override
//    public List<Goods> listGoods(Goods goods) {
//        return goodsDao.selectList(goods);
//    }
//
//    @Override
//    public void delGoodsById(Long goodsId) {
//        if (goodsId == null || goodsId <= 0) {
//            throw new AppException(ErrorMessage.GOODS_ID_CAN_NOT_BE_NULL_OR_UNDER_ZERO);
//        }
//        goodsDao.delete(goodsId);
//    }
//
//    @Override
//    public void addGoods(Goods goods) {
//
//        //条码，规格，图片暂设可为空
//        if (StringUtil.isEmpty(goods.getGoodsName())) {
//            throw new AppException(ErrorMessage.GOODS_NAME_CAN_NOT_BE_NULL);
//        }
//        if (null == goods.getGoodsType()) { // by 贾俊峰：商品类型编号为Long型
//            throw new AppException(ErrorMessage.GOODS_TYPE_CAN_NOT_BE_NULL_OR_INCORRECT);
//        }
//        if (null == goods.getGoodsMarketPrice() || goods.getGoodsMarketPrice() <= 0) {
//            throw new AppException(ErrorMessage.GOODS_MARKET_PRICE_CAN_NOT_BE_NULL);
//        }
//        if (null == goods.getGoodsSellPrice() || goods.getGoodsSellPrice() <= 0) {
//            throw new AppException(ErrorMessage.GOODS_SELL_PRICE_CAN_NOT_BE_NULL);
//        }
//        if (null == goods.getGoodsSettlementPrice() || goods.getGoodsSettlementPrice() <= 0) {
//            throw new AppException(ErrorMessage.GOODS_SETTLEMENT_PRICE_CAN_NOT_BE_NULL);
//        }
//        if (StringUtil.isEmpty(goods.getGoodsUnit())) {
//            throw new AppException(ErrorMessage.GOODS_UNIT_CAN_NOT_BE_NULL);
//        }
//        goods.setOrgId(658965487556L);
//        Organization organization = organizationDao.selectOne(658965487556L);
//        goods.setGoodsId(goodsIdWorker.createId());
//        goods.setGoodsStatus(GoodsStatus.PUBLISH.getValue());
//        goods.setOrgName(organization.getOrgName());
//        goods.setCreateTime(new Date());
//        goods.setUpdateTime(new Date());
//        goodsDao.insert(goods);
//    }

    //	@Override
//	public Goods selectOne(Long goodsId) {
//		if (goodsId == null || goodsId <= 0) {
//            throw new AppException(ErrorMessage.GOODS_ID_CAN_NOT_BE_NULL_OR_UNDER_ZERO);
//        }
//		return goodsDao.selectOne(goodsId);
//	}
//    @Override
//    public void editGoods(Goods goods) {
//        //条码，规格，图片暂设可为空
//        if (StringUtil.isEmpty(goods.getGoodsName().trim())) {
//            throw new AppException(ErrorMessage.GOODS_NAME_CAN_NOT_BE_NULL);
//        }
//
////		if(null == goods.getGoodsType() || goods.getGoodsType() < 0 ||goods.getGoodsType() >= 100){
//        if (null == goods.getGoodsType()) { // by 贾俊峰：商品类型编号为Long型
//            throw new AppException(ErrorMessage.GOODS_TYPE_CAN_NOT_BE_NULL_OR_INCORRECT);
//        }
//        /*if(null == goods.getGoodsMarketPrice() || goods.getGoodsMarketPrice() <= 0){
//			throw new AppException(ErrorMessage.GOODS_MARKET_PRICE_CAN_NOT_BE_NULL);
//		}*/
//        if (null == goods.getGoodsSellPrice() || goods.getGoodsSellPrice() <= 0) {
//            throw new AppException(ErrorMessage.GOODS_SELL_PRICE_CAN_NOT_BE_NULL);
//        }
//        if (null == goods.getGoodsSettlementPrice() || goods.getGoodsSettlementPrice() <= 0) {
//            throw new AppException(ErrorMessage.GOODS_SETTLEMENT_PRICE_CAN_NOT_BE_NULL);
//        }
//        if (StringUtil.isEmpty(goods.getGoodsUnit().trim())) {
//            throw new AppException(ErrorMessage.GOODS_UNIT_CAN_NOT_BE_NULL);
//        }
//        if (null == goods.getGoodsStatus() || goods.getGoodsStatus() < 0 || goods.getGoodsStatus() >= 10) {
//            throw new AppException(ErrorMessage.GOODS_STATUS_CAN_NOT_BE_NULL_OR_INCORRECT);
//        }
//        Goods model = goodsDao.selectOne(goods.getGoodsId());
//        model.setGoodsName(goods.getGoodsName());
//        model.setGoodsType(goods.getGoodsType());
//        model.setGoodsSellPrice(goods.getGoodsSellPrice());
//        model.setGoodsSettlementPrice(goods.getGoodsSettlementPrice());
//        model.setGoodsUnit(goods.getGoodsUnit());
//        if (StringUtil.isNotEmpty(goods.getGoodsImg().trim())) {
//            model.setGoodsImg(goods.getGoodsImg());
//        }
//        model.setGoodsStatus(goods.getGoodsStatus());
//        model.setUpdateTime(new Date());
//        goodsDao.update(model);
//    }
//
//    @Override
//    public void batchDelGoods(String goodsIdStr) {
//        if (goodsIdStr == null || goodsIdStr.length() == 0) {
//            throw new AppException(ErrorMessage.REQUEST_PARAM_CAN_NOT_NULL);
//        }
//        String[] goodsIdArr = goodsIdStr.split(",");
//        List<Long> goodsIdList = new ArrayList<>();
//        for (String goodsId : goodsIdArr) {
//            try {
//                Long id = Long.parseLong(goodsId);
//                goodsIdList.add(id);
//            } catch (NumberFormatException ex) {
//                throw new AppException(ErrorMessage.REQUEST_PARAM_TYPE_ERROR);
//            }
//        }
//        if (goodsIdList.size() != 0) {
//            goodsDao.batchDelete(goodsIdList);
//        }
//    }

}
